from Base import Base
from selenium.webdriver.common.by import By
import time

class Page(Base):
    login_loc = (By.CLASS_NAME,'link-login')
    def login(self):
        self.click(self.login_loc)

    username_loc = (By.ID,'loginname')
    def username(self):
        self.send_keys(self.username_loc,'19261033422')

    password_loc = (By.ID,'nloginpwd')
    def password(self):
        self.send_keys(self.password_loc,'yukaiwen2580')

    login_btn = (By.ID,'loginsubmit')
    def loginbtn(self):
        self.click(self.login_btn)

    search_loc = (By.XPATH,'/html/body/div[3]/div/div[1]/div/div[1]/div/div/div[2]/div/div/input')
    def search(self):
        self.send_keys(self.search_loc,'智能手机')

    search_btn = (By.CLASS_NAME,'btn')
    def searchbtn(self):
        self.click(self.search_btn)

    text_01_te = (By.XPATH,'/html/body/div[6]/div[2]/div[1]/div/ul/li[1]/div/div[2]/a/div[2]')
    text_01_pr = (By.XPATH,'/html/body/div[6]/div[2]/div[1]/div/ul/li[1]/div/div[2]/a/div[1]/span')
    def text01(self):
        print(self.text(self.text_01_te))
        print(self.text(self.text_01_pr))

    text_02_te = (By.XPATH, '/html/body/div[6]/div[2]/div[1]/div/ul/li[2]/div/div[2]/a/div[2]')
    text_02_pr = (By.XPATH, '/html/body/div[6]/div[2]/div[1]/div/ul/li[2]/div/div[2]/a/div[1]/span')
    def text02(self):
        print(self.text(self.text_02_te))
        print(self.text(self.text_02_pr))

    text_03_te = (By.XPATH, '/html/body/div[6]/div[2]/div[1]/div/ul/li[3]/div/div[2]/a/div[2]')
    text_03_pr = (By.XPATH, '/html/body/div[6]/div[2]/div[1]/div/ul/li[3]/div/div[2]/a/div[1]/span')
    def text03(self):
        print(self.text(self.text_03_te))
        print(self.text(self.text_03_pr))

    text_04_te = (By.XPATH, '/html/body/div[6]/div[2]/div[1]/div/ul/li[4]/div/div[2]/a/div[2]')
    text_04_pr = (By.XPATH, '/html/body/div[6]/div[2]/div[1]/div/ul/li[4]/div/div[2]/a/div[1]/span')
    def text04(self):
        print(self.text(self.text_04_te))
        print(self.text(self.text_04_pr))

    text_05_te = (By.XPATH, '/html/body/div[6]/div[2]/div[1]/div/ul/li[5]/div/div[2]/a/div[2]')
    text_05_pr = (By.XPATH, '/html/body/div[6]/div[2]/div[1]/div/ul/li[5]/div/div[2]/a/div[1]/span')
    def text05(self):
        print(self.text(self.text_05_te))
        print(self.text(self.text_05_pr))

    def luoji_01_search(self,driver):
        try:
            po = Page(driver)
            po.login()
            po.username()
            po.password()
            po.loginbtn()
            time.sleep(6)
            po.search()
            po.searchbtn()
            po.switch()
            time.sleep(3)
            assert '智能手机' in str(self.driver.title)
            print(self.driver.title)
            po.save()
            po.text01()
            po.text02()
            po.text03()
            po.text04()
            po.text05()
        except Exception as e:
            print(e)
            Base(driver).save()